package com.wanglianyun.controller;

import com.wanglianyun.aspect.DS;
import com.wanglianyun.aspect.ReplaceVarify;
import com.wanglianyun.entity.StudentEntity;
import com.wanglianyun.entity.TeacherEntity;
import com.wanglianyun.mapper.db1.StudentMapper;
import com.wanglianyun.mapper.db2.TeacherMapper;
import com.wanglianyun.request.DemoRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class HelloController {

    @Resource
    StudentMapper studentMapper;

    @Resource
    TeacherMapper teacherMapper;

    @GetMapping("/student")
    @DS("studentDataSource")
    public String student(@RequestParam String name, @RequestParam int age) {
        StudentEntity studentEntity = new StudentEntity(name, age);
        studentMapper.insert(studentEntity);
        return "hello student";
    }

    @GetMapping("/teacher")
    @DS("teacherDataSource")
    public String teacher(@RequestParam String name, @RequestParam int age) {
        teacherMapper.insert(new TeacherEntity(name, age));
        return "hello teacher";
    }

    @PostMapping("/test")
    @ReplaceVarify
    public String test(@RequestBody  DemoRequest request) {
        System.out.println(request.getName());
        return "test";
    }
}